package inc
{
	import components.DataUtil;
	
	import flash.net.SharedObject;
	import flash.net.URLRequest;
	import flash.net.navigateToURL;
	
	import mx.rpc.events.ResultEvent;
	
	public class Config
	{
		public function Config()
		{
		}
		
		private static var dev:Boolean = true;  //是否本机？
		private static var project:String = "lottery";
		private static var localPath:String = "http://localhost:8080/";
		private static var netPath:String = "http://inlet3.newline666.us/"; //注意/结尾
		
		public static var flexDir:String = "bin/";
		public static var css_incPath:String = "extStyle/inc.swf";
		
		public static function getBasePath():String{
			if(dev){
				return localPath;
			}else{
				return netPath;
			}
		}
		
		public static function getAdminPath():String{
			return "Admin.html";
		}
		
		public static function getHomePath():String{
			return "Home.html";
		}
		//检查管理员进入权限
		public static function checkAdminAccess():void{
			var data:DataUtil = new DataUtil();
			data.send(getBasePath()+"admin-user-checkAdminAccess",
				checkResult);
			function checkResult(e:ResultEvent):void{
				if(e.result.data == 0){
					//验证失败
					navigateToURL(new URLRequest("App.html"), "_top");
				}
			}
		}
		//记住用户
		public static function addUserId(uid:int, username:String=null):void{
			var share:SharedObject = SharedObject.getLocal(project, "/");
			share.data.userId = uid;
			share.data.uid = uid;
			if(username!=null)
				share.data.username = username;
		}
		
		public static function getUserId():int{
			var share:SharedObject = SharedObject.getLocal(project, "/");
			if(share.data.userId!=null){
				var uid:int = int(share.data.userId);
				return uid;
			}
			return -1;
		}
		
		public static function goLogin():void{
			navigateToURL(new URLRequest("App.html"), "_top");
		}
		
		public static function goHome():void{
			navigateToURL(new URLRequest("Home.html"), "_top");
		}
	}
}